﻿using System;

namespace XbmcManager.Modules
{
    public class XbmcMuteManager
    {
        private XbmcController xbmc;

        private int currentVolume = 100;
        const int maxVolume = 100;
        const double softMuteVolume = .75;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Xbmc"></param>
        internal XbmcMuteManager(XbmcController Xbmc)
        {
            this.xbmc = Xbmc;
        }

        /// <summary>
        /// Mutes the volume to a percent less than current volume.
        /// </summary>
        public void SoftMute()
        {
            String strVol =  xbmc.Application.GetProperty(XbmcApplication.AppProperties.Volume);

            if (strVol != "") currentVolume = Int32.Parse(strVol);
            else currentVolume = maxVolume;

            xbmc.Application.Volume((int)(currentVolume * softMuteVolume), true);
        }

        /// <summary>
        /// Used if the volume is changed while it is soft muted
        /// </summary>
        /// <param name="newVolume">The new volume (not including softmute)</param>
        internal void VolumeChanged(int newVolume)
        {
            currentVolume = newVolume;

            xbmc.Application.Volume(currentVolume / 2, true);
        }

        /// <summary>
        /// Returns XBMC to its original volume
        /// </summary>
        public void UnMute()
        {
            xbmc.Application.Volume(currentVolume, true);
        }
    }
}
